import java.util.Random;
import java.util.ArrayList;
/*
 * A solar system.
 * 
 * @author Michelle Partogi, Araya Zaesim, Stanley Ayzenberg,  Adam Perez
 * @version 1.0
 */

public class SolarSystem {
	private static Random generator = new Random();
	private String name;
	private Coordinate coordinate;
	private static ArrayList<Coordinate> coordArray = new ArrayList<Coordinate>();
	private int techLevel;
	private String resource;
	public String size;
	private String government;
	private String techLevelName;
	private String event;
	private int[] goods = new int[10];
	
	/* 
	 * Constructs a solar system with name, tech level, coordinates (x, y)
	 * and special resource level.
	 * 
	 * 
	 * Tech Level
	 * - 0 Pre-Agriculture
	 * - 1 Agriculture
	 * - 2 Medieval
	 * - 3 Renaissance
	 * - 4 Early Industrial
	 * - 5 Industrial
	 * - 6 Post-Industrial
	 * - 7 Hi-Tech
	 * 
	 * 
	 * Resources
	 * - 0 NOSPECIALRESOURCES (the most common)
	 * - 1 MINERALRICH
	 * - 2 MINERALPOOR
	 * - 3 DESERT
	 * - 4 LOTSOFWATER
	 * - 5 RICHSOIL
	 * - 6 POORSOIL
	 * - 7 RICHFAUNA
	 * - 8 LIFELESS
	 * - 9 WEIRDMUSHROOMS
	 * - 10 LOTSOFHERBS
	 * - 11 ARTISTIC
	 * - 12 WARLIKE
	 * 
	 * 
	 * 
	 * Size
	 * - 0 Small
	 * - 1 Medium
	 * - 2 Large
	 * 
	 * @param name
	 */
	
	public SolarSystem (String name){
		this.name = name;
		this.coordinate = makeCoord(); //Make sure no coordinates are the same
		coordArray.add(this.coordinate);
		
		
		//1 in 10 chance there'll be an event
		techLevel = generator.nextInt(8); //from 0 to 7
		
		String[] resourceChoose = {"Mineral Rich",
				"Mineral Poor", "Desert","Lots of Water","Rich Soil","Poor Soil",
				"Rich Fauna", "Lifeless", "Weird Mushrooms", "Lots of Herbs", "Artistic",
				"Warlike", };
		int tempInt2 = generator.nextInt(18);
		if (tempInt2<12){
			this.resource = resourceChoose[tempInt2];
		}
		else{
			this.resource = "No Special Resources";
		}
		
		String[] sizeChoose = {"Small", "Medium", "Large"};
		this.size = sizeChoose[generator.nextInt(3)];
		if (Goods.WATER.getMTLP() <= techLevel) {
			goods[0] = generator.nextInt(50)+2;
		}
		if (Goods.FURS.getMTLP() <= techLevel) {
			goods[1] = generator.nextInt(50)+2;
		}
		if (Goods.FOOD.getMTLP() <= techLevel) {
			goods[2] = generator.nextInt(50)+2;
		}
		if (Goods.ORE.getMTLP() <= techLevel) {
			goods[3] = generator.nextInt(50)+2;
		}
		if (Goods.GAMES.getMTLP() <= techLevel) {
			goods[4] = generator.nextInt(50)+2;
		}
		if (Goods.FIREARMS.getMTLP() <= techLevel) {
			goods[5] = generator.nextInt(50+2);
		}
		if (Goods.MEDICINE.getMTLP() <= techLevel) {
			goods[6] = generator.nextInt(50)+2;
		}
		if (Goods.MACHINES.getMTLP() <= techLevel) {
			goods[7] = generator.nextInt(50)+2;
		}
		if (Goods.NARCOTICS.getMTLP() <= techLevel) {
			goods[8] = generator.nextInt(50)+2;
		}
		if (Goods.ROBOTS.getMTLP() <= techLevel) {
			goods[9] = generator.nextInt(50)+2;
		}
		
		@SuppressWarnings("unused")
		String wat = "wer";
	}
	
	/*
	 * Get names
	 * 
	 * @return name
	 */
	
	public String getName(){
		return name;
	}
	/*
	 * Get x
	 * 
	 * @return x
	 */
	public int getX(){
		return coordinate.x;
	}
	/*
	 * Get y
	 * 
	 * @return y
	 */
	public int getY(){
		return coordinate.y;
	}
	/*
	 * Make Coordinate for solar system
	 *  * If x,y matches another solar system, change x,y to something else
	 *  
	 *  @return Coordinates
	 */
	public Coordinate makeCoord(){
		int x = generator.nextInt(300);
		int y = generator.nextInt(300);
		Coordinate hello = new Coordinate(x,y);
		for (Coordinate item: coordArray){
			if (hello.equals(item)){
				hello = makeCoord();
				break;
			}
		}
		return hello;
	}
	
	/*
	 * Private inner class that holds coordinates x,y
	 * 
	 */
	
	private class Coordinate{
		public int x;
		public int y;
		
		/*
		 * constructs Coordinates based on x,y
		 * 
		 * @param x
		 * @param y
		 * 
		 */
		
		public Coordinate(int x, int y){
			this.x = x;
			this.y = y;
		}
	
	}//end coordinate
	public String getTechLevelName() {
		if (techLevel == 0) {
			techLevelName = "Pre-Agriculture";
		}
		else if (techLevel == 1) {
			techLevelName = "Agriculture";
		}
		else if (techLevel == 2) {
			techLevelName = "Medieval";
		}
		else if (techLevel == 3) {
			techLevelName = "Renaissance";
		}
		else if (techLevel == 4) {
			techLevelName = "Early Industrial";
		}
		else if (techLevel == 5) {
			techLevelName = "Industrial";
		}
		else if (techLevel == 6) {
			techLevelName = "Post-Industrial";
		}
		else if (techLevel == 7) {
			techLevelName = "Hi-Tech";
		}
		return techLevelName;
	}
	public int getTechLevel() {
		return techLevel;
	}
	public String getResource() {
		return resource;
	}
	public String getGovernment() {
		return government;
	}
	public String getEvent() {
		return event;
	}
	public String getSize() {
		return size;
	}
	public float getDistance(SolarSystem system2) {
		float distance = (float) Math.sqrt(((coordinate.x- system2.getX())*(coordinate.x- system2.getX()))+((coordinate.y-system2.getY())*(coordinate.y-system2.getY())));
		return distance;
	}
	public void setGoods(int[] goods) {
		this.goods = goods;
	}
	public int[] getGoods() {
		return goods;
//		MarketPlaceLogic logic = new MarketPlaceLogic(this, null);
//		return logic.buyPrices();
	}
}
